﻿using System;
using Shuba.Model;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Data.Common;
using System.Data;

namespace Shuba.Data
{
    public class ProspectProgress
    {
        public ProspectProgress()
        { 

        }

        public void SaveProspectProgress(ProspectProgressInfo INFO)
        {
            Database db = DBConnection.CreateDatabase();

            DbCommand cmd = db.GetSqlStringCommand(@"
                                UPDATE TBL_PROSPECT_PROGRESS_TMP
                                SET 
                                    PROSPECT_ID = @PROSPECT_ID
                                    ,PROGRESS_STATUS = @PROGRESS_STATUS
                                    ,UPDATE_BY = @UPDATE_BY
                                    ,UPDATE_DATE = @UPDATE_DATE
                                    ,UPLOAD_BY = @UPLOAD_BY
                                    ,UPLOAD_DATE = @UPLOAD_DATE
                                WHERE (PROSPECT_ID = @PROSPECT_ID) AND (PROGRESS_STATUS = @PROGRESS_STATUS);
                                IF @@ROWCOUNT = 0
                                INSERT INTO TBL_PROSPECT_PROGRESS_TMP
                                (
                                    PROSPECT_ID
                                    ,PROGRESS_STATUS
                                    ,ENTRY_BY
                                    ,ENTRY_DATE
                                    ,UPDATE_BY
                                    ,UPDATE_DATE
                                    ,UPLOAD_BY
                                    ,UPLOAD_DATE
                                    ,IS_UPLOAD
                                ) 
                                VALUES
                                (
                                    @PROSPECT_ID
                                    ,@PROGRESS_STATUS
                                    ,@ENTRY_BY
                                    ,@ENTRY_DATE
                                    ,@UPDATE_BY
                                    ,@UPDATE_DATE
                                    ,@UPLOAD_BY
                                    ,@UPLOAD_DATE
                                    ,'1'
                                );
                            ");
            db.AddInParameter(cmd, "@PROSPECT_ID", DbType.String, INFO.PROSPECT_ID);
            db.AddInParameter(cmd, "@PROGRESS_STATUS", DbType.String, INFO.PROGRESS_STATUS);
            db.AddInParameter(cmd, "@ENTRY_BY", DbType.String, INFO.ENTRY_BY);
            db.AddInParameter(cmd, "@ENTRY_DATE", DbType.DateTime, INFO.ENTRY_DATE);
            db.AddInParameter(cmd, "@UPDATE_BY", DbType.String, INFO.UPDATE_BY);
            db.AddInParameter(cmd, "@UPDATE_DATE", DbType.DateTime, INFO.UPDATE_DATE);
            db.AddInParameter(cmd, "@UPLOAD_BY", DbType.String, INFO.UPLOAD_BY);
            db.AddInParameter(cmd, "@UPLOAD_DATE", DbType.DateTime, INFO.UPLOAD_DATE);
            db.ExecuteNonQuery(cmd);
        }
    }
}